package com.example.yuejianapp14.Activity.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.yuejianapp14.Activity.Activity.ClassActivity;
import com.example.yuejianapp14.Activity.Activity.GameActivity;
import com.example.yuejianapp14.Activity.JavaBean.Act;
import com.example.yuejianapp14.Activity.JavaBean.Game;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 张森 on 2017/10/16.
 */

public class GameAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private List<Game> mDataList;
    private LayoutInflater mLayoutInflater;

    public GameAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflater.from(parent.getContext()).inflate(R.layout.gamecard,parent,false);
        return new GameAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Game entity = (Game) mDataList.get(position);
        if (null == entity)
            return;
        GameAdapter.ViewHolder viewHolder = (GameAdapter.ViewHolder) holder;
        viewHolder.Game_name.setText(entity.getCompetition());



        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/competition/"+entity.getPic()).into(viewHolder.Game_pic);
        // viewHolder.news_stars.setRating(Float.parseFloat(entity.get("news_stars").toString()));
        // viewHolder.news_thumb.setIIntegemageResource(r.parseInt(entity.get("news_thumb").toString()));
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,GameActivity.class);
                intent.putExtra("gameid",entity.getCompetitionid());
                intent.putExtra("gamename",entity.getCompetition());
                intent.putExtra("gamelink",entity.getLink());
                intent.putExtra("gamepic",entity.getPic());

                mContext.startActivity(intent);
            }
        });





    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView Game_pic;
        TextView Game_name;
        LinearLayout Game_container;

        public ViewHolder(View itemView) {
            super(itemView);
            Game_name = (TextView) itemView.findViewById(R.id.game_name);
            Game_pic = (ImageView) itemView.findViewById(R.id.game_pic);
            Game_container = (LinearLayout) itemView.findViewById(R.id.game_container);
        }
    }
}
